
import re
from xml.etree import ElementTree as ET
import sys
import json


def clean_mybatis_sql(sql):
    # 移除MyBatis动态标签
    try:
        root = ET.fromstring(f"<root>{sql}</root>")
        for elem in root.iter():
            if elem.tag not in ['root']:
                elem.clear()
        sql = ET.tostring(root, encoding='unicode', method='text')
    except:
        pass

    # 替换参数占位符
    sql = re.sub(r'[#${].+?}', '1', sql)
    return sql.strip()

def extract_tables(sql):
    cleaned_sql = clean_mybatis_sql(sql)
    # 提取FROM和JOIN后的表名
    tables = set()
    from_matches = re.finditer(r'(?i)\bFROM\s+([\w.]+)(?:\s+AS\s+[\w]+)?', cleaned_sql)
    join_matches = re.finditer(r'(?i)(?:INNER|LEFT|RIGHT|FULL)\s+JOIN\s+([\w.]+)(?:\s+AS\s+[\w]+)?', cleaned_sql)

    for match in from_matches:
        tables.add(match.group(1))
    for match in join_matches:
        tables.add(match.group(1))

    return sorted(tables)


#
# if len(sys.argv) > 1:
#     # print("第一个参数:", sys.argv[1])
#     sql = sys.argv[1]
#     sql = sql.replace("\n", "")
#     tableRes = extract_tables(sql)
#     print(tableRes)
# else:
#     print("没有提供待解析的SQL参数")
#




# if __name__ == '__main__':
#     # sql = "SELECT \r\n    t1.create_by AS grantPerson,\r\n    t1.create_time AS grantTime,\r\n    t2.name AS appCnName,\r\n    t2.app_en_name AS appEnName,\r\n    t2.app_leader AS appLeader,\r\n    t2.id AS clientId \r\n    FROM client_auth t1 INNER JOIN CLIENT t2 ON t1.client_id = t2.id \r\n    WHERE 1 = 1\r\n    <if test=\"apiId != null and apiId !='' \" > \r\n      and t1.api_id = #{apiId}\r\n    </if>\r\n    <if test=\"appLeader != null and appLeader !='(' \" > \r\n    and t2.app_leader like #{appLeader} \r\n    </if>\r\n    <if test=\"grantPerson != null and grantPerson !=')' \" > \r\n      and t1.create_by like #{grantPerson} \r\n    </if>\r\n    <if test=\"clientName != null and clientName !='' \" > \r\n      and (t2.name like #{clientName} or t2.app_en_name like #{clientName} )\r\n    </if> \r\n    LIMIT #{queryOffset}, #{querySize}\r\nLIMIT #{queryOffset}, #{querySize}"
#     sql = "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtaumeng_info_new\nwhere ym_code=200\nand dt>= '20230601'\nand dt&lt; '20240901'\ngroup by substr(dt,1,6) LIMIT 1000000"
#
#     sqlList = [
#         "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtaumeng_info_new\nwhere ym_code=200\nand dt>= '20230601'\nand dt&lt; '20240901'\ngroup by substr(dt,1,6) LIMIT 1000000",
#         "select fee_month,count(1) as cnt \nfrom\n (select *,\n case when substr(dt,7,2)>='16' then substr(\n cast(date_add(concat(substr(dt,1,4),'-',substr(dt,5,2),'-',substr(dt,7,2)),20) as varchar),1,7) \n else concat(substr(dt,1,4),'-',substr(dt,5,2))\n end as fee_month\n from \n ods_vds.ext_rtaty_info\nwhere ty_code=200\nand dt>= '20230616'\nand dt&lt;= '20230915') a\ngroup by fee_month LIMIT 1000000",
#         "with\n t1 as (\n select\n dlake_rip_us.prod_variable_res_online_hive.varname, \n dlake_rip_us.prod_variable_res_online_hive.varvalue, \n dlake_rip_us.prod_variable_res_online_hive.callid \n from \n dlake_rip_us.prod_variable_res_online_hive\n where\n dlake_rip_us.prod_variable_res_online_hive.varname = 'lastAObyOPLoanDatediff'\n and dlake_rip_us.prod_variable_res_online_hive.dt = '20240116'\n order by dlake_rip_us.prod_variable_res_online_hive.rowkey asc\n limit\n 500\n ), \n t2 as (\n select\n dlake_rip_us.prod_var_req_event_online_hive.traceid, \n dlake_rip_us.prod_var_req_event_online_hive.callid\n from \n dlake_rip_us.prod_var_req_event_online_hive\n join t1 on t1.callid = dlake_rip_us.prod_var_req_event_online_hive.callid\n where\n dlake_rip_us.prod_var_req_event_online_hive.dt = '20240116'\n and dlake_rip_us.prod_var_req_event_online_hive.traceid != 'null'\n )\n, \n\n t3 as (\n select\n dlake_rip_us.process_approve_base_info.uniqueid, \n dlake_rip_us.process_approve_base_info.traceid\n from \n dlake_rip_us.process_approve_base_info\n join t2 on t2.traceid = dlake_rip_us.process_approve_base_info.traceid\n where\n dlake_rip_us.process_approve_base_info.dt = '20240116'\n )\nselect\n t1.*, \n t2.*, \n t3.* \nfrom\n t2\n join t3 on t3.traceid = t2.traceid\n join t1 on t2.callid = t1.callid",
#         "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtajg_info\nwhere jg_code='200'\nand dt>= '20230601'\nand dt&lt; date_format(current_date(), 'yyyyMM01')\ngroup by substr(dt,1,6) LIMIT 1000000",
#         "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtaumeng_info_new\nwhere ym_code='200'\nand dt>= '20230601'\nand dt&lt; date_format(current_date(), 'yyyyMM01')\ngroup by substr(dt,1,6) LIMIT 1000000",
#         "select\n dlake_rip_us.process_approve_base_info.applyno,\n dlake_rip_us.process_approve_base_info.scenetype,\n dlake_rip_us.process_approve_base_info.tradeno\nfrom\n dlake_rip_us.process_approve_base_info\n join dlake_rip_us.process_approve_datanode_event on dlake_rip_us.process_approve_datanode_event.traceid = dlake_rip_us.process_approve_base_info.traceid\n join dlake_rip_us.process_approve_dataprod_relation on dlake_rip_us.process_approve_dataprod_relation.traceid = dlake_rip_us.process_approve_datanode_event.traceid\nwhere\n dlake_rip_us.process_approve_base_info.dt = '20230914'\n and dlake_rip_us.process_approve_datanode_event.dt = '20230914'\n and dlake_rip_us.process_approve_dataprod_relation.dt = '20230914'\n and dlake_rip_us.process_approve_datanode_event.datanodeid = 'ServiceTask_CSW01Run2a'\n and dlake_rip_us.process_approve_dataprod_relation.dataprodid in (\n 'DPM_AF_147101',\n 'DPM_AF_151601',\n 'DPM_AF_27401',\n 'DPM_AF_130901',\n 'DPM_AF_124101',\n 'DPM_AF_118901',\n 'GCLM_DEBT_RATE_REALTIME',\n 'DPM_AF_98301',\n 'DPM_AF_43601',\n 'DPM_AF_88601',\n 'DPM_AF_71801',\n 'DPM_AF_35501',\n 'DPM_AF_105701',\n 'DPM_AF_103401',\n 'DPM_AF_91201',\n 'DPM_AF_37801',\n 'DPM_AF_81501',\n 'DPM_AF_139601',\n 'DPM_AF_34001',\n 'DPM_AF_96701',\n 'DPM_AF_99801',\n 'DPM_AF_106901',\n 'DPM_AF_19301',\n 'DPM_AF_104601',\n 'DPM_AF_73401',\n 'DPM_AF_92701',\n 'DPM_AF_151501',\n 'DPM_AF_124001',\n 'DPM_AF_75801',\n 'DPM_AF_40401',\n 'DPM_AF_49101',\n 'GL_cash_uplimit_02',\n 'DPM_AF_84601',\n 'selfrunCreditPolicyPboc2',\n 'DPM_AF_105801',\n 'DPM_AF_127401',\n 'DPM_AF_38701',\n 'DPM_AF_25001',\n 'DPM_AF_87801',\n 'DPM_AF_72601',\n 'DPM_AF_41201',\n 'DPM_AF_139501',\n 'mgt_br311_01',\n 'pboc_credit2',\n 'DPM_AF_49801',\n 'DPM_AF_43501',\n 'DPM_AF_105901',\n 'DPM_AF_98201',\n 'mgt_br525',\n 'DPM_AF_88501',\n 'DPM_AF_71901',\n 'DPM_AF_126201',\n 'DPM_AF_19401',\n 'DPM_AF_38001',\n 'DPM_AF_130701',\n 'DPM_AF_73501',\n 'DPM_AF_118701',\n 'MGT_BR234_01',\n 'DPM_AF_90501',\n 'DPM_AF_103601',\n 'DPM_AF_91101',\n 'DPM_AF_127301',\n 'DPM_AF_96801',\n 'DPM_AF_115201',\n 'DPM_AF_72001',\n 'DPM_AF_131801',\n 'DPM_AF_139401',\n 'DPM_AF_27301',\n 'DPM_AF_81401',\n 'DPM_AF_34101',\n 'DPM_AF_41301',\n 'mgt_br524',\n 'eay04_duxiaoman_multiloans',\n 'DPM_AF_126101',\n 'MGT_BR299_03',\n 'DPM_AF_75701',\n 'DPM_AF_84701',\n 'DPM_AF_118601',\n 'DPM_AF_96001',\n 'DPM_AF_65201',\n 'DPM_AF_20201',\n 'DPM_AF_92601',\n 'DPM_AF_109001',\n 'DPM_AF_22801',\n 'm1_B20081101_pboc2var1',\n 'DPM_AF_120801',\n 'pboc2_gaa02_vars_expert',\n 'mgtBR04501ModlePboc2',\n 'DPM_AF_87901',\n 'DPM_AF_127201',\n 'DPM_AF_115101',\n 'DPM_AF_35601',\n 'DPM_AF_131701',\n 'DPM_AF_33901',\n 'DPM_AF_38801',\n 'mgt_br048_01',\n 'DPM_AF_139301',\n 'DPM_AF_72501',\n 'DPM_AF_23401',\n 'DPM_AF_96501',\n 'DPM_AF_82501',\n 'DPM_AF_10801',\n 'm1_B20080302_pboc2',\n 'DPM_AF_75201',\n 'DPM_AF_114701',\n 'DPM_AF_105301',\n 'DPM_AF_103001',\n 'DPM_AF_107601',\n 'm1_b20102101_pboc2_tx',\n 'DPM_AF_73601',\n 'DPM_AF_126801',\n 'DPM_AF_115801',\n 'DPM_AF_84501',\n 'DPM_AF_88801',\n 'DPM_AF_62401',\n 'DPM_AF_80901',\n 'DPM_AF_71601',\n 'DPM_AF_106501',\n 'DPM_AF_104201',\n 'DPM_AF_126701',\n 'DPM_AF_39301',\n 'DPM_AF_35001',\n 'DPM_AF_88001',\n 'DPM_AF_72401',\n 'DPM_AF_116901',\n 'DPM_AF_23701',\n 'baidu_nzd_dpd_2022_bh',\n 'DPM_AF_87301',\n 'DPM_AF_105401',\n 'DPM_AF_103101',\n 'selfrunCreditPolicyUuidContrCashNo',\n 'DPM_AF_107701',\n 'DPM_AF_35701',\n 'DPM_AF_82201',\n 'DPM_AF_25901',\n 'DPM_AF_73901',\n 'DPM_AF_115701',\n 'DPM_AF_43801',\n 'DPM_AF_31401',\n 'DPM_AF_108901',\n 'DPM_AF_149601',\n 'GCLM_DEBT_RATE',\n 'DPM_AF_25701',\n 'DPM_AF_85001',\n 'DPM_AF_124301',\n 'DPM_AF_10901',\n 'DPM_AF_73701',\n 'DPM_AF_92301',\n 'DPM_AF_116801',\n 'DPM_AF_82401',\n 'DPM_AF_96601',\n 'DPM_AF_103201',\n 'DPM_AF_85901',\n 'DPM_AF_105501',\n 'DPM_AF_107801',\n 'DPM_AF_84401',\n 'DPM_AF_88701',\n 'DPM_AF_49201',\n 'DPM_AF_62301',\n 'DPM_AF_71701',\n 'DPM_AF_19201',\n 'DPM_AF_115601',\n 'mgt_br046_01',\n 'DPM_AF_140901',\n 'DPM_AF_75101',\n 'DPM_AF_104401',\n 'DPM_AF_106701',\n 'DPM_AF_37901',\n 'DPM_AF_124201',\n 'DPM_AF_27901',\n 'DPM_AF_102101',\n 'DPM_AF_101401',\n 'vce2to1_pboc_batch',\n 'model_xhed_br',\n 'DPM_AF_116701',\n 'mgtBR04801ModlePboc2',\n 'DPM_AF_23601',\n 'DPM_AF_107901',\n 'DPM_AF_103301',\n 'DPM_AF_72301',\n 'DPM_AF_105601',\n 'DPM_AF_43701',\n 'DPM_AF_115501',\n 'DPM_AF_139701',\n 'DPM_AF_26401',\n 'DPM_AF_73801',\n 'DPM_AF_82301',\n 'DPM_AF_106801',\n 'DPM_AF_104501',\n 'DPM_AF_100001',\n 'DPM_AF_141001',\n 'GL_cash_dti_02',\n 'DPM_AF_49501',\n 'DPM_AF_23101',\n 'DPM_AF_75401',\n 'DPM_AF_93901',\n 'DPM_AF_85101',\n 'DPM_AF_47901',\n 'DPM_AF_31201',\n 'DPM_AF_97101',\n 'consumeCreditPolicyPboc2V2',\n 'DPM_AF_87401',\n 'mgt_br043_01',\n 'DPM_AF_131201',\n 'DPM_AF_85801',\n 'DPM_AF_90801',\n 'mgt_br519',\n 'DPM_AF_69601',\n 'DPM_AF_106101',\n 'DPM_AF_152001',\n 'DPM_AF_64901',\n 'DPM_AF_101501',\n 'DPM_AF_146801',\n 'DPM_AF_92401',\n 'DPM_AF_144501',\n 'DPM_AF_82701',\n 'DPM_AF_82001',\n 'DPM_AF_88901',\n 'DPM_AF_89001',\n 'DPM_AF_97801',\n 'vce2to1_pboc3',\n 'DPM_AF_91601',\n 'DPM_AF_88201',\n 'mgt_br518',\n 'DPM_AF_42501',\n 'DPM_AF_131101',\n 'DPM_AF_154201',\n 'DPM_AF_146701',\n 'DPM_AF_96301',\n 'DPM_AF_81801',\n 'pboc2_gaa02_datamodel_batch_vars',\n 'DPM_AF_75301',\n 'DPM_AF_47801',\n 'DPV_AF_01101',\n 'pboc2_gaa02_anyihua_vars',\n 'DPM_AF_114901',\n 'DPM_AF_100101',\n 'consumeCreditPolicyPboc2',\n 'DPM_AF_121201',\n 'DPM_AF_101601',\n 'DPM_AF_119001',\n 'DPM_AF_40201',\n 'DPM_AF_92501',\n 'pboc2_vars_inner',\n 'DPM_AF_35201',\n 'DPM_AF_72901',\n 'DPM_AF_82601',\n 'MGT_BR047_01',\n 'DPM_AF_87501',\n 'MGT_BR233_01',\n 'DPM_AF_104001',\n 'DPM_AF_106301',\n 'DPV_AF_02101',\n 'DPM_AF_146601',\n 'DPM_AF_85701',\n 'DPM_AF_23001',\n 'custInnovationPboc2',\n 'baidu_credit_score',\n 'DPM_AF_97901',\n 'DPM_AF_62501',\n 'DPM_AF_69501',\n 'DPM_AF_88101',\n 'DPM_AF_114801',\n 'DPM_AF_97001',\n 'DPM_AF_91001',\n 'DPM_AF_96901',\n 'DPM_AF_43901',\n 'DPM_AF_82101',\n 'm1_b20122801',\n 'DPM_AF_105201',\n 'DPM_AF_35101',\n 'DPM_AF_126901',\n 'DPM_AF_90901',\n 'DPM_AF_81901',\n 'mod01_5103_pboc2_multi_mob6',\n 'vce2to1_pboc1',\n 'DPM_AF_121101',\n 'DPM_AF_146501',\n 'DPM_AF_42401',\n 'DPM_AF_31301',\n 'pboc2_gaa02_datamodel_fqyx_vars',\n 'DPM_AF_96401',\n 'DPM_AF_98101',\n 'DPM_AF_91501',\n 'DPM_AF_106401',\n 'DPM_AF_81001',\n 'DPM_AF_104101',\n 'MGT_BR512_01',\n 'DPM_AF_91401',\n 'DPM_AF_87601',\n 'DPM_AF_72801',\n 'DPM_AF_42601',\n 'DPM_AF_90601',\n 'DPM_AF_118501',\n 'DPM_AF_69801',\n 'DPM_AF_43401',\n 'DPM_AF_88401',\n 'DPM_AF_130501',\n 'DPM_AF_109101',\n 'DPM_AF_111301',\n 'pboc2_bfloantaf',\n 'DPM_AF_120701',\n 'DPM_AF_19501',\n 'DPM_AF_38101',\n 'DPM_AF_141401',\n 'br_multiapply_blaze',\n 'DPM_AF_102701',\n 'DPM_AF_100201',\n 'DPM_AF_127101',\n 'DPM_AF_115001',\n 'DPM_AF_131601',\n 'DPM_AF_35301',\n 'MGT_BR510_01',\n 'DPM_AF_94201',\n 'DPM_AF_139201',\n 'DPM_AF_108001',\n 'DPM_AF_40301',\n 'DPM_AF_121801',\n 'DPM_AF_37601',\n 'mgt_br526',\n 'DPM_AF_130401',\n 'DPM_AF_111401',\n 'DPM_AF_109201',\n 'DPM_AF_74101',\n 'DPM_AF_143601',\n 'DPM_AF_141301',\n 'DPM_AF_96101',\n 'DPM_AF_102801',\n 'DPM_AF_28001',\n 'DPM_AF_131501',\n 'DPM_AF_127001',\n 'DPM_AF_117201',\n 'DPM_AF_71301',\n 'DPM_AF_108101',\n 'DPM_AF_121701',\n 'DPM_AF_144801',\n 'baidu_multiloans10',\n 'vce2to1_pboc_htyh',\n 'DPM_AF_101801',\n 'DPM_AF_130301',\n 'DPM_AF_64801',\n 'DPM_AF_35401',\n 'DPM_AF_99901',\n 'DPM_AF_31101',\n 'DPM_AF_111501',\n 'DPM_AF_109301',\n 'DPM_AF_50601',\n 'DPM_AF_141201',\n 'DPM_AF_42701',\n 'DPM_AF_91301',\n 'DPM_AF_87701',\n 'DPM_AF_145801',\n 'DPM_AF_72701',\n 'mgt_br517',\n 'DPM_AF_102901',\n 'DPM_AF_98401',\n 'DPM_AF_117101',\n 'DPM_AF_100301',\n 'DPM_AF_82801',\n 'DPM_AF_131401',\n 'DPM_AF_112701',\n 'DPM_AF_26001',\n 'DPM_AF_139001',\n 'DPM_AF_144701',\n 'DPM_AF_90701',\n 'DPM_AF_69701',\n 'DPM_AF_74001',\n 'DPM_AF_111601',\n 'DPM_AF_109401',\n 'DPM_AF_107101',\n 'DPM_AF_141101',\n 'DPM_AF_81201',\n 'DPM_AF_40501',\n 'mgt_br516',\n 'DPM_AF_49701',\n 'DPM_AF_50501',\n 'DPM_AF_117001',\n 'DPM_AF_152101',\n 'DPM_AF_96201',\n 'DPM_AF_131301',\n 'DPM_AF_112801',\n 'm1_b21011101',\n 'mgt_br045_01',\n 'DPM_AF_28101',\n 'DPM_AF_106001',\n 'DPM_AF_101901',\n 'DPM_AF_92801',\n 'DPM_AF_24701',\n 'DPM_AF_146901',\n 'DPM_AF_144601',\n 'DPM_AF_88301',\n 'DPM_AF_37501'\n )\n and dlake_rip_us.process_approve_dataprod_relation.callstatus in ('success', 'skipAndSuccess')\ngroup by\n dlake_rip_us.process_approve_base_info.traceid,\n dlake_rip_us.process_approve_base_info.applyno,\n dlake_rip_us.process_approve_base_info.tradeno,\n dlake_rip_us.process_approve_base_info.scenetype LIMIT 1000000",
#         "select \r\n * \r\nfrom rip_dcssvc_realtime.decision_fv_de2203010001_af_online\r\n where dt = '20240924'\r\n and va2i7b_luma_api_black_check_lumaapi_black_check_result_black is null\r\n limit 2",
#         "select\n ${in_param}\nfrom\n dlake_rip_us.process_approve_base_info\n join dlake_rip_us.prod_variable_res_online_store_hive on dlake_rip_us.prod_variable_res_online_store_hive.traceid = dlake_rip_us.process_approve_base_info.traceid\nwhere\n dlake_rip_us.prod_variable_res_online_store_hive.dt = '${dt}'\n and dlake_rip_us.prod_variable_res_online_store_hive.varname = '${varname}'\n and dlake_rip_us.process_approve_base_info.dt = '${dt}'\nLIMIT\n 1000",
#         "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtayz2_info\nwhere yz_code=200\nand dt>= '20230601'\nand dt&lt; '20240901'\ngroup by substr(dt,1,6) LIMIT 1000000",
#         "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtajg_info\nwhere jg_code=200\nand dt>= '20230601'\nand dt&lt; '20240901'\ngroup by substr(dt,1,6) LIMIT 1000000"
#                ]
#
#     resSet = set()
#     for sql in sqlList:
#         tables = extract_tables(sql)
#         print(tables)
#         resSet = resSet.union(tables)
#
#     print(resSet)



def load_json_data(filepath):
    try:   # 读取json文件
        with open(filepath, 'r', encoding='utf-8') as f:
            json_str = json.load(f)
        return json_str
    except (FileNotFoundError, json.JSONDecodeError) as e:    # 捕获异常
        print(f"Error: {e}")
        return None


if __name__ == '__main__':

    data = load_json_data("C:\\Users\\guoqiang.bai\\Desktop\\a.json")
    data_ = data["data"]

    resSet = set()

    nameTableMap = dict()


    for ele in data_:
        task_ = ele["task"]

        loads = json.loads(task_)
        loads_ = loads[0]
        list_ = loads_["sqlList"]

        sqlList = list_[0]

        sql_text_ = sqlList["sqlText"]

        name_ = ele["name"]
        tables = extract_tables(sql_text_)
        print(tables)

        get = nameTableMap.get(name_)
        if get is None:
            get = set()
            for e in tables :
                get.add(e)
            nameTableMap[name_] = get
        else:
            for e in tables:
                get.add(e)




    print("================================")
    print("================================")
    print(nameTableMap)


    #
    #
    # # sql = "SELECT \r\n    t1.create_by AS grantPerson,\r\n    t1.create_time AS grantTime,\r\n    t2.name AS appCnName,\r\n    t2.app_en_name AS appEnName,\r\n    t2.app_leader AS appLeader,\r\n    t2.id AS clientId \r\n    FROM client_auth t1 INNER JOIN CLIENT t2 ON t1.client_id = t2.id \r\n    WHERE 1 = 1\r\n    <if test=\"apiId != null and apiId !='' \" > \r\n      and t1.api_id = #{apiId}\r\n    </if>\r\n    <if test=\"appLeader != null and appLeader !='(' \" > \r\n    and t2.app_leader like #{appLeader} \r\n    </if>\r\n    <if test=\"grantPerson != null and grantPerson !=')' \" > \r\n      and t1.create_by like #{grantPerson} \r\n    </if>\r\n    <if test=\"clientName != null and clientName !='' \" > \r\n      and (t2.name like #{clientName} or t2.app_en_name like #{clientName} )\r\n    </if> \r\n    LIMIT #{queryOffset}, #{querySize}\r\nLIMIT #{queryOffset}, #{querySize}"
    # sql = "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtaumeng_info_new\nwhere ym_code=200\nand dt>= '20230601'\nand dt&lt; '20240901'\ngroup by substr(dt,1,6) LIMIT 1000000"
    #
    # sqlList = [
    #     "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtaumeng_info_new\nwhere ym_code=200\nand dt>= '20230601'\nand dt&lt; '20240901'\ngroup by substr(dt,1,6) LIMIT 1000000",
    #     "select fee_month,count(1) as cnt \nfrom\n (select *,\n case when substr(dt,7,2)>='16' then substr(\n cast(date_add(concat(substr(dt,1,4),'-',substr(dt,5,2),'-',substr(dt,7,2)),20) as varchar),1,7) \n else concat(substr(dt,1,4),'-',substr(dt,5,2))\n end as fee_month\n from \n ods_vds.ext_rtaty_info\nwhere ty_code=200\nand dt>= '20230616'\nand dt&lt;= '20230915') a\ngroup by fee_month LIMIT 1000000",
    #     "with\n t1 as (\n select\n dlake_rip_us.prod_variable_res_online_hive.varname, \n dlake_rip_us.prod_variable_res_online_hive.varvalue, \n dlake_rip_us.prod_variable_res_online_hive.callid \n from \n dlake_rip_us.prod_variable_res_online_hive\n where\n dlake_rip_us.prod_variable_res_online_hive.varname = 'lastAObyOPLoanDatediff'\n and dlake_rip_us.prod_variable_res_online_hive.dt = '20240116'\n order by dlake_rip_us.prod_variable_res_online_hive.rowkey asc\n limit\n 500\n ), \n t2 as (\n select\n dlake_rip_us.prod_var_req_event_online_hive.traceid, \n dlake_rip_us.prod_var_req_event_online_hive.callid\n from \n dlake_rip_us.prod_var_req_event_online_hive\n join t1 on t1.callid = dlake_rip_us.prod_var_req_event_online_hive.callid\n where\n dlake_rip_us.prod_var_req_event_online_hive.dt = '20240116'\n and dlake_rip_us.prod_var_req_event_online_hive.traceid != 'null'\n )\n, \n\n t3 as (\n select\n dlake_rip_us.process_approve_base_info.uniqueid, \n dlake_rip_us.process_approve_base_info.traceid\n from \n dlake_rip_us.process_approve_base_info\n join t2 on t2.traceid = dlake_rip_us.process_approve_base_info.traceid\n where\n dlake_rip_us.process_approve_base_info.dt = '20240116'\n )\nselect\n t1.*, \n t2.*, \n t3.* \nfrom\n t2\n join t3 on t3.traceid = t2.traceid\n join t1 on t2.callid = t1.callid",
    #     "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtajg_info\nwhere jg_code='200'\nand dt>= '20230601'\nand dt&lt; date_format(current_date(), 'yyyyMM01')\ngroup by substr(dt,1,6) LIMIT 1000000",
    #     "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtaumeng_info_new\nwhere ym_code='200'\nand dt>= '20230601'\nand dt&lt; date_format(current_date(), 'yyyyMM01')\ngroup by substr(dt,1,6) LIMIT 1000000",
    #     "select\n dlake_rip_us.process_approve_base_info.applyno,\n dlake_rip_us.process_approve_base_info.scenetype,\n dlake_rip_us.process_approve_base_info.tradeno\nfrom\n dlake_rip_us.process_approve_base_info\n join dlake_rip_us.process_approve_datanode_event on dlake_rip_us.process_approve_datanode_event.traceid = dlake_rip_us.process_approve_base_info.traceid\n join dlake_rip_us.process_approve_dataprod_relation on dlake_rip_us.process_approve_dataprod_relation.traceid = dlake_rip_us.process_approve_datanode_event.traceid\nwhere\n dlake_rip_us.process_approve_base_info.dt = '20230914'\n and dlake_rip_us.process_approve_datanode_event.dt = '20230914'\n and dlake_rip_us.process_approve_dataprod_relation.dt = '20230914'\n and dlake_rip_us.process_approve_datanode_event.datanodeid = 'ServiceTask_CSW01Run2a'\n and dlake_rip_us.process_approve_dataprod_relation.dataprodid in (\n 'DPM_AF_147101',\n 'DPM_AF_151601',\n 'DPM_AF_27401',\n 'DPM_AF_130901',\n 'DPM_AF_124101',\n 'DPM_AF_118901',\n 'GCLM_DEBT_RATE_REALTIME',\n 'DPM_AF_98301',\n 'DPM_AF_43601',\n 'DPM_AF_88601',\n 'DPM_AF_71801',\n 'DPM_AF_35501',\n 'DPM_AF_105701',\n 'DPM_AF_103401',\n 'DPM_AF_91201',\n 'DPM_AF_37801',\n 'DPM_AF_81501',\n 'DPM_AF_139601',\n 'DPM_AF_34001',\n 'DPM_AF_96701',\n 'DPM_AF_99801',\n 'DPM_AF_106901',\n 'DPM_AF_19301',\n 'DPM_AF_104601',\n 'DPM_AF_73401',\n 'DPM_AF_92701',\n 'DPM_AF_151501',\n 'DPM_AF_124001',\n 'DPM_AF_75801',\n 'DPM_AF_40401',\n 'DPM_AF_49101',\n 'GL_cash_uplimit_02',\n 'DPM_AF_84601',\n 'selfrunCreditPolicyPboc2',\n 'DPM_AF_105801',\n 'DPM_AF_127401',\n 'DPM_AF_38701',\n 'DPM_AF_25001',\n 'DPM_AF_87801',\n 'DPM_AF_72601',\n 'DPM_AF_41201',\n 'DPM_AF_139501',\n 'mgt_br311_01',\n 'pboc_credit2',\n 'DPM_AF_49801',\n 'DPM_AF_43501',\n 'DPM_AF_105901',\n 'DPM_AF_98201',\n 'mgt_br525',\n 'DPM_AF_88501',\n 'DPM_AF_71901',\n 'DPM_AF_126201',\n 'DPM_AF_19401',\n 'DPM_AF_38001',\n 'DPM_AF_130701',\n 'DPM_AF_73501',\n 'DPM_AF_118701',\n 'MGT_BR234_01',\n 'DPM_AF_90501',\n 'DPM_AF_103601',\n 'DPM_AF_91101',\n 'DPM_AF_127301',\n 'DPM_AF_96801',\n 'DPM_AF_115201',\n 'DPM_AF_72001',\n 'DPM_AF_131801',\n 'DPM_AF_139401',\n 'DPM_AF_27301',\n 'DPM_AF_81401',\n 'DPM_AF_34101',\n 'DPM_AF_41301',\n 'mgt_br524',\n 'eay04_duxiaoman_multiloans',\n 'DPM_AF_126101',\n 'MGT_BR299_03',\n 'DPM_AF_75701',\n 'DPM_AF_84701',\n 'DPM_AF_118601',\n 'DPM_AF_96001',\n 'DPM_AF_65201',\n 'DPM_AF_20201',\n 'DPM_AF_92601',\n 'DPM_AF_109001',\n 'DPM_AF_22801',\n 'm1_B20081101_pboc2var1',\n 'DPM_AF_120801',\n 'pboc2_gaa02_vars_expert',\n 'mgtBR04501ModlePboc2',\n 'DPM_AF_87901',\n 'DPM_AF_127201',\n 'DPM_AF_115101',\n 'DPM_AF_35601',\n 'DPM_AF_131701',\n 'DPM_AF_33901',\n 'DPM_AF_38801',\n 'mgt_br048_01',\n 'DPM_AF_139301',\n 'DPM_AF_72501',\n 'DPM_AF_23401',\n 'DPM_AF_96501',\n 'DPM_AF_82501',\n 'DPM_AF_10801',\n 'm1_B20080302_pboc2',\n 'DPM_AF_75201',\n 'DPM_AF_114701',\n 'DPM_AF_105301',\n 'DPM_AF_103001',\n 'DPM_AF_107601',\n 'm1_b20102101_pboc2_tx',\n 'DPM_AF_73601',\n 'DPM_AF_126801',\n 'DPM_AF_115801',\n 'DPM_AF_84501',\n 'DPM_AF_88801',\n 'DPM_AF_62401',\n 'DPM_AF_80901',\n 'DPM_AF_71601',\n 'DPM_AF_106501',\n 'DPM_AF_104201',\n 'DPM_AF_126701',\n 'DPM_AF_39301',\n 'DPM_AF_35001',\n 'DPM_AF_88001',\n 'DPM_AF_72401',\n 'DPM_AF_116901',\n 'DPM_AF_23701',\n 'baidu_nzd_dpd_2022_bh',\n 'DPM_AF_87301',\n 'DPM_AF_105401',\n 'DPM_AF_103101',\n 'selfrunCreditPolicyUuidContrCashNo',\n 'DPM_AF_107701',\n 'DPM_AF_35701',\n 'DPM_AF_82201',\n 'DPM_AF_25901',\n 'DPM_AF_73901',\n 'DPM_AF_115701',\n 'DPM_AF_43801',\n 'DPM_AF_31401',\n 'DPM_AF_108901',\n 'DPM_AF_149601',\n 'GCLM_DEBT_RATE',\n 'DPM_AF_25701',\n 'DPM_AF_85001',\n 'DPM_AF_124301',\n 'DPM_AF_10901',\n 'DPM_AF_73701',\n 'DPM_AF_92301',\n 'DPM_AF_116801',\n 'DPM_AF_82401',\n 'DPM_AF_96601',\n 'DPM_AF_103201',\n 'DPM_AF_85901',\n 'DPM_AF_105501',\n 'DPM_AF_107801',\n 'DPM_AF_84401',\n 'DPM_AF_88701',\n 'DPM_AF_49201',\n 'DPM_AF_62301',\n 'DPM_AF_71701',\n 'DPM_AF_19201',\n 'DPM_AF_115601',\n 'mgt_br046_01',\n 'DPM_AF_140901',\n 'DPM_AF_75101',\n 'DPM_AF_104401',\n 'DPM_AF_106701',\n 'DPM_AF_37901',\n 'DPM_AF_124201',\n 'DPM_AF_27901',\n 'DPM_AF_102101',\n 'DPM_AF_101401',\n 'vce2to1_pboc_batch',\n 'model_xhed_br',\n 'DPM_AF_116701',\n 'mgtBR04801ModlePboc2',\n 'DPM_AF_23601',\n 'DPM_AF_107901',\n 'DPM_AF_103301',\n 'DPM_AF_72301',\n 'DPM_AF_105601',\n 'DPM_AF_43701',\n 'DPM_AF_115501',\n 'DPM_AF_139701',\n 'DPM_AF_26401',\n 'DPM_AF_73801',\n 'DPM_AF_82301',\n 'DPM_AF_106801',\n 'DPM_AF_104501',\n 'DPM_AF_100001',\n 'DPM_AF_141001',\n 'GL_cash_dti_02',\n 'DPM_AF_49501',\n 'DPM_AF_23101',\n 'DPM_AF_75401',\n 'DPM_AF_93901',\n 'DPM_AF_85101',\n 'DPM_AF_47901',\n 'DPM_AF_31201',\n 'DPM_AF_97101',\n 'consumeCreditPolicyPboc2V2',\n 'DPM_AF_87401',\n 'mgt_br043_01',\n 'DPM_AF_131201',\n 'DPM_AF_85801',\n 'DPM_AF_90801',\n 'mgt_br519',\n 'DPM_AF_69601',\n 'DPM_AF_106101',\n 'DPM_AF_152001',\n 'DPM_AF_64901',\n 'DPM_AF_101501',\n 'DPM_AF_146801',\n 'DPM_AF_92401',\n 'DPM_AF_144501',\n 'DPM_AF_82701',\n 'DPM_AF_82001',\n 'DPM_AF_88901',\n 'DPM_AF_89001',\n 'DPM_AF_97801',\n 'vce2to1_pboc3',\n 'DPM_AF_91601',\n 'DPM_AF_88201',\n 'mgt_br518',\n 'DPM_AF_42501',\n 'DPM_AF_131101',\n 'DPM_AF_154201',\n 'DPM_AF_146701',\n 'DPM_AF_96301',\n 'DPM_AF_81801',\n 'pboc2_gaa02_datamodel_batch_vars',\n 'DPM_AF_75301',\n 'DPM_AF_47801',\n 'DPV_AF_01101',\n 'pboc2_gaa02_anyihua_vars',\n 'DPM_AF_114901',\n 'DPM_AF_100101',\n 'consumeCreditPolicyPboc2',\n 'DPM_AF_121201',\n 'DPM_AF_101601',\n 'DPM_AF_119001',\n 'DPM_AF_40201',\n 'DPM_AF_92501',\n 'pboc2_vars_inner',\n 'DPM_AF_35201',\n 'DPM_AF_72901',\n 'DPM_AF_82601',\n 'MGT_BR047_01',\n 'DPM_AF_87501',\n 'MGT_BR233_01',\n 'DPM_AF_104001',\n 'DPM_AF_106301',\n 'DPV_AF_02101',\n 'DPM_AF_146601',\n 'DPM_AF_85701',\n 'DPM_AF_23001',\n 'custInnovationPboc2',\n 'baidu_credit_score',\n 'DPM_AF_97901',\n 'DPM_AF_62501',\n 'DPM_AF_69501',\n 'DPM_AF_88101',\n 'DPM_AF_114801',\n 'DPM_AF_97001',\n 'DPM_AF_91001',\n 'DPM_AF_96901',\n 'DPM_AF_43901',\n 'DPM_AF_82101',\n 'm1_b20122801',\n 'DPM_AF_105201',\n 'DPM_AF_35101',\n 'DPM_AF_126901',\n 'DPM_AF_90901',\n 'DPM_AF_81901',\n 'mod01_5103_pboc2_multi_mob6',\n 'vce2to1_pboc1',\n 'DPM_AF_121101',\n 'DPM_AF_146501',\n 'DPM_AF_42401',\n 'DPM_AF_31301',\n 'pboc2_gaa02_datamodel_fqyx_vars',\n 'DPM_AF_96401',\n 'DPM_AF_98101',\n 'DPM_AF_91501',\n 'DPM_AF_106401',\n 'DPM_AF_81001',\n 'DPM_AF_104101',\n 'MGT_BR512_01',\n 'DPM_AF_91401',\n 'DPM_AF_87601',\n 'DPM_AF_72801',\n 'DPM_AF_42601',\n 'DPM_AF_90601',\n 'DPM_AF_118501',\n 'DPM_AF_69801',\n 'DPM_AF_43401',\n 'DPM_AF_88401',\n 'DPM_AF_130501',\n 'DPM_AF_109101',\n 'DPM_AF_111301',\n 'pboc2_bfloantaf',\n 'DPM_AF_120701',\n 'DPM_AF_19501',\n 'DPM_AF_38101',\n 'DPM_AF_141401',\n 'br_multiapply_blaze',\n 'DPM_AF_102701',\n 'DPM_AF_100201',\n 'DPM_AF_127101',\n 'DPM_AF_115001',\n 'DPM_AF_131601',\n 'DPM_AF_35301',\n 'MGT_BR510_01',\n 'DPM_AF_94201',\n 'DPM_AF_139201',\n 'DPM_AF_108001',\n 'DPM_AF_40301',\n 'DPM_AF_121801',\n 'DPM_AF_37601',\n 'mgt_br526',\n 'DPM_AF_130401',\n 'DPM_AF_111401',\n 'DPM_AF_109201',\n 'DPM_AF_74101',\n 'DPM_AF_143601',\n 'DPM_AF_141301',\n 'DPM_AF_96101',\n 'DPM_AF_102801',\n 'DPM_AF_28001',\n 'DPM_AF_131501',\n 'DPM_AF_127001',\n 'DPM_AF_117201',\n 'DPM_AF_71301',\n 'DPM_AF_108101',\n 'DPM_AF_121701',\n 'DPM_AF_144801',\n 'baidu_multiloans10',\n 'vce2to1_pboc_htyh',\n 'DPM_AF_101801',\n 'DPM_AF_130301',\n 'DPM_AF_64801',\n 'DPM_AF_35401',\n 'DPM_AF_99901',\n 'DPM_AF_31101',\n 'DPM_AF_111501',\n 'DPM_AF_109301',\n 'DPM_AF_50601',\n 'DPM_AF_141201',\n 'DPM_AF_42701',\n 'DPM_AF_91301',\n 'DPM_AF_87701',\n 'DPM_AF_145801',\n 'DPM_AF_72701',\n 'mgt_br517',\n 'DPM_AF_102901',\n 'DPM_AF_98401',\n 'DPM_AF_117101',\n 'DPM_AF_100301',\n 'DPM_AF_82801',\n 'DPM_AF_131401',\n 'DPM_AF_112701',\n 'DPM_AF_26001',\n 'DPM_AF_139001',\n 'DPM_AF_144701',\n 'DPM_AF_90701',\n 'DPM_AF_69701',\n 'DPM_AF_74001',\n 'DPM_AF_111601',\n 'DPM_AF_109401',\n 'DPM_AF_107101',\n 'DPM_AF_141101',\n 'DPM_AF_81201',\n 'DPM_AF_40501',\n 'mgt_br516',\n 'DPM_AF_49701',\n 'DPM_AF_50501',\n 'DPM_AF_117001',\n 'DPM_AF_152101',\n 'DPM_AF_96201',\n 'DPM_AF_131301',\n 'DPM_AF_112801',\n 'm1_b21011101',\n 'mgt_br045_01',\n 'DPM_AF_28101',\n 'DPM_AF_106001',\n 'DPM_AF_101901',\n 'DPM_AF_92801',\n 'DPM_AF_24701',\n 'DPM_AF_146901',\n 'DPM_AF_144601',\n 'DPM_AF_88301',\n 'DPM_AF_37501'\n )\n and dlake_rip_us.process_approve_dataprod_relation.callstatus in ('success', 'skipAndSuccess')\ngroup by\n dlake_rip_us.process_approve_base_info.traceid,\n dlake_rip_us.process_approve_base_info.applyno,\n dlake_rip_us.process_approve_base_info.tradeno,\n dlake_rip_us.process_approve_base_info.scenetype LIMIT 1000000",
    #     "select \r\n * \r\nfrom rip_dcssvc_realtime.decision_fv_de2203010001_af_online\r\n where dt = '20240924'\r\n and va2i7b_luma_api_black_check_lumaapi_black_check_result_black is null\r\n limit 2",
    #     "select\n ${in_param}\nfrom\n dlake_rip_us.process_approve_base_info\n join dlake_rip_us.prod_variable_res_online_store_hive on dlake_rip_us.prod_variable_res_online_store_hive.traceid = dlake_rip_us.process_approve_base_info.traceid\nwhere\n dlake_rip_us.prod_variable_res_online_store_hive.dt = '${dt}'\n and dlake_rip_us.prod_variable_res_online_store_hive.varname = '${varname}'\n and dlake_rip_us.process_approve_base_info.dt = '${dt}'\nLIMIT\n 1000",
    #     "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtayz2_info\nwhere yz_code=200\nand dt>= '20230601'\nand dt&lt; '20240901'\ngroup by substr(dt,1,6) LIMIT 1000000",
    #     "select substr(dt,1,6) as data_month,count(1) as cnt \nfrom ods_vds.ext_rtajg_info\nwhere jg_code=200\nand dt>= '20230601'\nand dt&lt; '20240901'\ngroup by substr(dt,1,6) LIMIT 1000000"
    #            ]
    #
    # resSet = set()
    # for sql in sqlList:
    #     tables = extract_tables(sql)
    #     print(tables)
    #     resSet = resSet.union(tables)

    # print(resSet)

